﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace Quanlybanhang_pro202.Module
{
    class Khachhang
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["quanlybanhang"].ToString());
        SqlCommand cmd;
        SqlDataAdapter sqlda;
        DataSet ds;

        public DataSet GetAllCustome()
        {
            try
            {
                conn.Open();
                cmd = new SqlCommand("select * from khachhang", conn);
                sqlda = new SqlDataAdapter();
                ds = new DataSet();
                sqlda.SelectCommand = cmd;
                sqlda.Fill(ds, "khachhang");
                return ds;
            }
            catch
            {
                throw;
            }
        }
        public int InsertCustomer(string hoten, string diachi, string sdt)
        {
            try
            {
                conn.Open();
                cmd = new SqlCommand("insert khachhang values(N'" + hoten + "',N'" + diachi + "',N'" + sdt + "')", conn);
                int i = cmd.ExecuteNonQuery();
                if (i > 0)
                {
                    return 1;

                }
                return 0;

            }
            catch
            {
                throw;
            }
        }
        public int UpdateCustome(int ID, string hoten, string diachi, string sdt)
        {

            try
            {
                conn.Open();
                cmd = new SqlCommand("update khachhang set hoten = '" + hoten + "',diachi = '" + diachi + "',sdt = '" + sdt + "' where makh = '"+ID+"'");
                int i = cmd.ExecuteNonQuery();
                if (i > 0)
                {
                    return 1;
                }
                return 0;

            }
            catch
            {
                throw;
            }

        }
        public int DeleteCustome(int ID)
        {
            try
            {
                conn.Open();
                cmd = new SqlCommand("delete khachhang where makh = '" + ID + "'", conn);
                int i = cmd.ExecuteNonQuery();
                if (i > 0)
                {
                    return 1;
                }
                return 0;

            }
            catch
            {
                throw;
            }
        }


    }
}
